
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/16/2014 17:14:15
-- Generated from EDMX file: C:\Users\DASTOR 6\Desktop\Konferensbokning\VS13\Projects\webBokning\Business\Data\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [konferensDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_booking_user]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[booking] DROP CONSTRAINT [FK_booking_user];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[booking]', 'U') IS NOT NULL
    DROP TABLE [dbo].[booking];
GO
IF OBJECT_ID(N'[dbo].[user]', 'U') IS NOT NULL
    DROP TABLE [dbo].[user];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'bookings'
CREATE TABLE [dbo].[bookings] (
    [bookingID] int IDENTITY(1,1) NOT NULL,
    [from] datetime  NOT NULL,
    [to] datetime  NOT NULL,
    [userID] int  NOT NULL,
    [roomID] int  NOT NULL
);
GO

-- Creating table 'users'
CREATE TABLE [dbo].[users] (
    [userID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(50)  NOT NULL,
    [email] nvarchar(200)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [bookingID] in table 'bookings'
ALTER TABLE [dbo].[bookings]
ADD CONSTRAINT [PK_bookings]
    PRIMARY KEY CLUSTERED ([bookingID] ASC);
GO

-- Creating primary key on [userID] in table 'users'
ALTER TABLE [dbo].[users]
ADD CONSTRAINT [PK_users]
    PRIMARY KEY CLUSTERED ([userID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [userID] in table 'bookings'
ALTER TABLE [dbo].[bookings]
ADD CONSTRAINT [FK_booking_user]
    FOREIGN KEY ([userID])
    REFERENCES [dbo].[users]
        ([userID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_booking_user'
CREATE INDEX [IX_FK_booking_user]
ON [dbo].[bookings]
    ([userID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------